package com.example.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.example.domian.po.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * ClassName: UserMapper
 * Package: com.example.mapper
 * Description:
 *
 * @Author: yyx
 * @Create: 2025/7/14 - 10:47
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {
@Select("update user set balance=balance-#{money} ${ew.customSqlSegment}")
    void updateBalanceById(@Param(Constants.WRAPPER) UpdateWrapper<User> wrapper, @Param("money") int money);
@Select("select u.* from user u inner join  address a on u.id=a.user_id ${ew.customSqlSegment} ")
    List<User> queryUserByMapper(@Param("ew") QueryWrapper<User> wrapper);
@Update("update user set balance=balance - #{money} where id = #{id}")
    void deductMoneyById(@Param("id") Long id, @Param("money") Integer money);
}
